package com.shiliao.app.activity.personal.ui;

import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.shiliao.app.R;
import com.shiliao.app.activity.personal.presenter.ContentRefereePresenter;
import com.shiliao.app.activity.personal.view.ContentRefereeView;
import com.shiliao.app.manager.YMUserManager;
import com.shiliao.app.utils.WebSetUtil;
import com.shiliao.app.utils.YMServerUtil;
import com.shiliao.app.weight.ActionBarView;
import com.shiliao.app.weight.ProgressWebView;
import com.yimei.framework.base.ui.BaseActivity;

import butterknife.BindView;

/**
 * Created by yinzhiqiang on 2018/4/19.
 */

public class ContentRefereeActivity extends BaseActivity implements ContentRefereeView{

    @BindView(R.id.webview)
    ProgressWebView webview;

    @BindView(R.id.title_bar)
    ActionBarView mActionBar;

    private ContentRefereePresenter contentRefereePresenter;
    @Override
    public int getLayoutId() {
        return R.layout.activity_content_referee;
    }

    @Override
    public void initView() {
        super.initView();
        mActionBar.setTitles("内容推荐");
        mActionBar.setBackClick(this);
        mActionBar.getBackView().setVisibility(View.VISIBLE);
        WebSetUtil.setWebView(webview);
        contentRefereePresenter=new ContentRefereePresenter(this);
        contentRefereePresenter.requestContentReferee(YMUserManager.getUserId(this));
        WebRef r=new WebRef();
        webview.setWebViewClient(r);
    }

    class WebRef extends WebViewClient {
        public WebRef() {
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            webview.loadUrl(url);
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

        }
    }

    @Override
    public void getContent(String content) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                webview.loadDataWithBaseURL(YMServerUtil.BASE_URL,
                        content, "text/html", "utf-8", null);
            }
        });

    }
}
